//
//  ZSBContactInfoCell.m
//  HCNewGoldFinger
//
//  Created by zjhcsoft on 14-10-15.
//  Copyright (c) 2014年 zjhcsoftios. All rights reserved.
//

#import "ZSBContactInfoCell.h"

#import <SDWebImage/UIImageView+WebCache.h>

@interface ZSBContactInfoCell()

@property (nonatomic, strong) UIImageView *headImageView;

@property (nonatomic, strong) UILabel *contentLab;

@property (nonatomic, strong) UIView *line;

@end

@implementation ZSBContactInfoCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.accessoryType = UITableViewCellAccessoryNone;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = [UIColor clearColor];
        self.autoresizesSubviews = YES;
        [self setUpView];
    }
    return self;
}
- (void)setUpView
{
    _headImageView = [[UIImageView alloc] initWithFrame:CGRectZero];
    _headImageView.userInteractionEnabled = NO;
    _headImageView.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:_headImageView];
    
    _contentLab = [[UILabel alloc] initWithFrame:CGRectZero];
    _contentLab.font = [UIFont systemFontOfSize:16];
    _contentLab.textColor = [UIColor blackColor];
    [self.contentView addSubview:_contentLab];
    
    
    _line = [[UIView alloc] initWithFrame:CGRectZero];
    [self.contentView addSubview:_line];
}
 - (void)layoutSubviews
{
    [super layoutSubviews];
    
    if (_contactInfo.contactType == ZSBContactTypeCompany) {
        _headImageView.frame = CGRectMake(10+self.indentationLevel*10, self.frame.size.height/2-6, 12, 12);
    }else{
        _headImageView.frame = CGRectMake(10+self.indentationLevel*10, 10, self.frame.size.height-20, self.frame.size.height-20);
    }
    _contentLab.frame = CGRectMake(self.frame.size.height+self.indentationLevel*10, 10, self.frame.size.width-self.frame.size.height, self.frame.size.height-20);
    _line.frame = CGRectMake(self.indentationLevel*10, self.frame.size.height-0.5, self.frame.size.width, 0.5);
}

- (void)prepareForReuse
{
    [super prepareForReuse];
    _headImageView.image = [UIImage imageNamed:@"icon_user111"];
}

- (void)setContactInfo:(ZSBContactInfo *)contactInfo
{
    _contactInfo = contactInfo;
    
    if (contactInfo.contactType == ZSBContactTypeCompany) {
        _contentLab.font = [UIFont boldSystemFontOfSize:16];
        _contentLab.text = contactInfo.companyName;
        if (_contactInfo.isExpansion == YES) {
            _headImageView.image = [UIImage imageNamed:@"icon_show"];
        }else{
            _headImageView.image = [UIImage imageNamed:@"icon_dis"];
        }
    }else{
        _contentLab.font = [UIFont systemFontOfSize:16];
        _contentLab.text = contactInfo.userName;
        if (_showCompany) {
            _contentLab.text = [NSString stringWithFormat:@"%@(%@)",contactInfo.userName,contactInfo.companyName];
        }
        
        [_headImageView sd_setImageWithURL:[NSURL URLWithString:_contactInfo.headImgUrl] completed:nil];
    }
    self.indentationLevel = contactInfo.level;
}

@end
